//
//  YGNavBarView.m
//  SunshineMall
//
//  Created by 张艳江 on 2018/10/31.
//  Copyright © 2018年 张艳江. All rights reserved.
//

#import "SCNavBarView.h"

@interface SCNavBarView()

@end

@implementation SCNavBarView

- (UIButton *)leftButton{
    if (!_leftButton) {
        _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftButton.frame = CGRectMake(5, kStatusBarHeight, 44, 44);
        [_leftButton addTarget:self action:@selector(clickLeftButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_leftButton];
    }
    return _leftButton;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        _rightButton = [UIButton new];
        _rightButton.frame = CGRectMake(kScreenW - 5 - 44, kStatusBarHeight, 44, 44);
        _rightButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [_rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _rightButton.adjustsImageWhenHighlighted = NO;
        [_rightButton addTarget:self action:@selector(clickRightButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_rightButton];
    }
    return _rightButton;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, kStatusBarHeight, kScreenW/2.0f, kNavBarHeight)];
        _titleLabel.centerX = kScreenW/2;
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = SCFont(17);
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, self.height - 0.5, kScreenW, 0.5)];
        _lineView.backgroundColor = RGB(239, 239, 239);
        [self addSubview:_lineView];
    }
    return _lineView;
}
- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self titleLabel];
        [self lineView];
    }
    return self;
}
#pragma mark - 点击按钮事件
- (void)clickLeftButton{
    if (self.leftButtonBlock) {
        self.leftButtonBlock();
    }
}
- (void)clickRightButton{
    if (self.rightButtonBlock) {
        self.rightButtonBlock();
    }
}

@end
